$.mcCube = {};
$.mcCube.theme = $.class.create({
    construct : function(name, config) {
        this.name   = name;
        this.config = config;
    },

    icon : function(name, attrs){
        return this.image('icons/'+ name, attrs).attr('height', 15);
    },

    image : function(name, attrs){
        return $('<img />').attr('src',
              this.config.image.path
            + name +'.'+ this.config.image.extension
        );
    }
});

$.mcCube.popin = $.class.create({
    construct : function(config) {
        this.config = $.extend({
            modal   : true,
            autoOpen: false
        }, config);
    },

    'alert' : function(msg, url){
        if(url){
            this.load(url);
        } els
        this.node.html(msg);
        return this;
    },

    'confirm' : function(msg, buttons, url){
        this.config = $.extend({}, {'button':buttons}, this.config);
        if(url){
            this.load(url);
        }

        this.node.html(msg);
        return this;
    },

    html : function(html){
        this.node.html(html);
        return this;
    },

    close : function(){
        $(this.node).dialog('close');
        this.node.remove();
        this.node = null;
        return this;
    },

    open : function(){
        this.create();
        this.node.dialog(this.config).dialog('open');
        return this;
    },

    load : function(url){
        var $this = this;
        $.mcCube.tools.ajax.post(
              url
            , function(datas){
                $this.create().html(datas).open();
            }
        );
        return this;
    },

    create : function(){
        if(!this.node){
            this.node = $('<div></div>')
            $('body').append(this.node);
        }
        return this;
    }
});

$.extends = {};
$.extends.slider = {
      'node'   : null
    , 'inDom'  : false

    /* - */
    , 'close'  : function(){
        this.node.detach();
    }
    , 'open'   : function(){

    }
    , 'close'  : function(){
        this.node.detach();
    }
    , 'toggle' : function(){
        this.inDom ? this.open() : this.close();
        this.inDom = !this.inDom;
    }
}

$.extends.actions = {
    /* - */
    fire : function(action) {
        if($.isFunction(this.config[action])) {
            this.config[action](this);
        }
        else if($.isPlainObject(this.config[action])) {
            if($.isFunction(this.config[action].onBefore)) {
                this.config[action].onBefore(this);
            }

            this[action](this.config[action]);

            if($.isFunction(this.config[action].onAfter)) {
                this.config[action].onAfter(this);
            }
        }
        else {
            this[action](this.config[action]);
        }
    }
}